import {History} from './History';

const histories:Array<History> = [];

let point:number = -1;

function getHistory(p:number):History{
  point = p;
  return histories[p];
}

function peek():History{
  return histories[point];
}

function pop():History{
  let history:History;
  history = histories[--point];
  return history;
}

function addHistory(history:History):void{
  histories[++point] = history;
  if(point > histories.length-1){
    histories.splice(point, histories.length-point);
  }
}

function getPoint():number{
  return point;
}

function getAllHistories():Array<History>{
  return histories;
}

export {
  getHistory,
  peek,
  addHistory,
  getPoint,
  getAllHistories,
  pop
};